package com.my.study.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadPoolUtil {

    /**
     * 线程池关闭
     *
     * @param executorService
     * @param timeout
     */
    public static void shutdown(ExecutorService executorService,long timeout){
        try {
            executorService.shutdown();
            if(!executorService.awaitTermination(timeout, TimeUnit.MILLISECONDS)){
                executorService.shutdownNow();
            }
        } catch (InterruptedException e) {
            log.error("线程池关闭失败",e);
        }
    }

}
